package com.awccis.common.service.impl;

import com.awccis.common.dao.CommonDao;
import com.awccis.common.model.Message;
import com.awccis.common.service.CommonService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author: 纯牛奶丶
 * @Date: 2018-03-31 0031 下午 09:43
 * @Since: 1.0
 * @Decription:
 **/
@Service
public class CommonServiceImpl implements CommonService {

    @Resource
    CommonDao commonDao;


    /**
     * 验证手机号是否存在的业务逻辑
     *
     * @param message message
     * @return true or false true为存在，false不存在
     */
    @Override
    public boolean checkPhoneNumber(Message message) {
        boolean flag;
        String userType = message.getUserType();
        switch (userType){
            case "driver":
                flag = commonDao.checkDriverPhoneNumber(message) == 1;
                break;
            case "customer":
                flag = commonDao.checkCustomerPhoneNumber(message) == 1;
                break;
            default:
                flag = true;
                break;
        }
        return flag;
    }

    /**
     * 根据手机号更改密码
     *
     * @param message
     * @return true or false true更改成功，false更改失败
     */
    @Override
    public boolean updatePwdByPhone(Message message) {
        boolean flag = false;
        String numberType = message.getNumberType();
        String customer = "customer";
        String driver = "driver";

        String phone = message.getPhone();
        if(customer.equals(numberType) && !"".equals(phone) && phone != null){
            commonDao.updateCustomerPwdByPhone(message);
            flag = true;
        }else if(driver.equals(numberType)){
            commonDao.updateDriverPwdByPhone(message);
            flag = true;
        }
        
        return flag;
    }
}
